package com.dv.chat;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.InetSocketAddress;

/**
 * @Author DavidLoman
 * @create 2021/5/3 17:21
 */
public class UdpSenderDemo01 {
    public static void main(String[] args) throws Exception{
        DatagramSocket socket = new DatagramSocket(8888);
        //准备数据:控制台读取system in
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

        while(true){

            String data = bufferedReader.readLine();
            byte[] dataBytes = data.getBytes();
            DatagramPacket packet = new DatagramPacket(dataBytes,0,dataBytes.length,new InetSocketAddress("localhost",6666));

            socket.send(packet);
            if (dataBytes.equals("bye")){
                break;
            }
        }
        socket.close();


    }
}
